package win.devhu.onestation.app;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.inject.AbstractModule;

import io.javalin.Javalin;
import io.javalin.plugin.json.JavalinJson;
import io.javalin.plugin.rendering.JavalinRenderer;
import io.javalin.plugin.rendering.template.JavalinPebble;


/**
 * Guice Module
 *
 */
public class ApplicationModule extends AbstractModule {
	private final Javalin app;

//	private Logger logger = LoggerFactory.getLogger(ApplicationModule.class);

	public ApplicationModule(Javalin app){
		this.app = app;

		//Configuring the JSON mapper
		Gson gson = new GsonBuilder().create();
		JavalinJson.setFromJsonMapper(gson::fromJson);
		JavalinJson.setToJsonMapper(gson::toJson);
		
		//配置模板后缀
		JavalinRenderer.register(JavalinPebble.INSTANCE, ".html",".peb", ".pebble");
		

	}

	/**
	 * Guice 依赖绑定
	 */
	@Override
	protected void configure() {
		bind(Javalin.class).toInstance(app);
		bind(Application.class);
	}
}